package com.wlz.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.wlz.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RestController()
@RequestMapping("/user")
public class UserController {

    @Autowired
    private FeignClientTestInterface feignClientTestInterface;
    @GetMapping("/getUser")
    @ResponseBody
    @SentinelResource(value = "getUser", blockHandlerClass = UserController.class,blockHandler = "getUserBlock")
    public UserVO getUserById(Integer id){
        UserVO userVO = new UserVO();
        userVO.setAge(20);
        userVO.setId(1);
        userVO.setName("小明");
        return userVO;
    }

    @GetMapping("/test")
    @SentinelResource(value = "user/test", blockHandlerClass = UserController.class,blockHandler = "getUserBlock")
    @ResponseBody
    public String test(){
        String result = feignClientTestInterface.helloWorld();
        return result;
    }


    public static String getUserBlock(BlockException e){
        return "接口 已被流控";
    }

}
